package com.business;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import com.business.wechat.service.WeixinUtils;

import net.sf.rose.boot.BootStrap;
import net.sf.rose.web.util.WebUtils;

@Configuration
@SpringBootApplication
// @EnableAspectJAutoProxy(proxyTargetClass = false)
@ComponentScan(basePackages = { "com.business", "net.sf.rose" })
public class MainApplication extends SpringBootServletInitializer implements EmbeddedServletContainerCustomizer {

	public static void main(String[] args) throws Exception {
		BootStrap.initial();
		WeixinUtils.initial();
		SpringApplication.run(MainApplication.class, args);
	}

	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
		return builder.sources(MainApplication.class);
	}

	@Override
	public void customize(ConfigurableEmbeddedServletContainer container) {
		WebUtils web = (WebUtils) BootStrap.getStartBean(WebUtils.class);
		if (web != null) {
			// 指定端口地址
			container.setPort(web.getPort());
			// 指定项目名称
			String contextPath = web.getContextPath();
			if (!contextPath.equals("")) {
				container.setContextPath(contextPath);
			}
		}
	}
}
